import { Application, codo } from "egg";
import Token from "./Token";
import Auth from "./Auth";
import Message from "./Message";
import User from "./User";
import Approval from "./Approval";
import SuiteApp from "./SuiteApp";
import SuiteCorp from "./SuiteCorp";

const symbolAuthService = Symbol("WeWorkService#auth");

/**
 */
export default class WeWorkService {
	constructor(protected appConfig: codo.WeWork.IWeWorkConfig, protected app: Application) {}

	get token() {
		if (!this[symbolAuthService]) {
			this[symbolAuthService] = new Token(this.appConfig, this.app);
		}
		return this[symbolAuthService] as Token;
	}

	/** 企业调用，认证授权相关，自建应用调用 */
	auth(access_token: string) {
		return new Auth(this.appConfig, access_token, this.app);
	}

	/** 第三方应用调用，部分常用接口 使用suite access token */
	suiteApp(suite_access_token: string) {
		return new SuiteApp(this.appConfig, suite_access_token, this.app);
	}

	/** 第三方应用下企业调用, 使用suite corp access token，跟企业的access token很类似 */
	suiteCorp(suite_corp_access_token: string) {
		return new SuiteCorp(this.appConfig, suite_corp_access_token, this.app);
	}

	message(access_token: string) {
		return new Message(this.appConfig, access_token, this.app);
	}

	user(access_token: string) {
		return new User(this.appConfig, access_token, this.app);
	}

	approval(access_token: string) {
		return new Approval(this.appConfig, access_token, this.app);
	}
}
